package com.bt.lms.ui.page.stu;

import com.bt.lms.ui.action.registration.stu.*;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Cursor;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.ScrollEvent;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;

/**
 * 编辑报名学员信息界面
 */
public class PageEditApplyStuInfo extends VBox {

    /**
     * 编辑报名学员信息界面长
     */
    private double preWidth = 1280;
    /**
     * 编辑报名学员信息界面高
     */
    private double preHeight = 800;

    /**
     * 标签默认长度
     */
    private double labDefaultWidth = 200;

    public PageEditApplyStuInfo(){

        this.setPrefSize(preWidth,preHeight);
        this.setPadding(new Insets(5));
        this.setSpacing(20);
        //顶部横向盒子
        HBox topHBox = new HBox();
        initTopHBox(topHBox);
        //编辑报名学员信息横向盒子
        HBox editApplyStuInfoHBox = new HBox();
        initEditApplyStuInfoHBox(editApplyStuInfoHBox);
        //帐号电子邮箱横向盒子
        HBox accountHBox = new HBox();
        initAccountHBox(accountHBox);
        //报名编号横向盒子
        HBox applyNumHBox = new HBox();
        initApplyNumHBox(applyNumHBox);
        //姓名横向盒子
        HBox nameHBox = new HBox();
        initNameHBox(nameHBox);
        //性别横向盒子
        HBox genderHBox = new HBox();
        initGenderHBox(genderHBox);
        //出生日期横向盒子
        HBox birthdayHBox = new HBox();
        initBirthdayHBox(birthdayHBox);
        //证件类型横向盒子
        HBox IDTypeHBox = new HBox();
        initIDTypeHBox(IDTypeHBox);
        //证件号码横向盒子
        HBox IDNumHBox = new HBox();
        initIDNumHBox(IDNumHBox);

        //所属招生计划横向盒子
        HBox ofEnPHBox = new HBox();
        initOfEnPHBox(ofEnPHBox);
        //电子邮箱横向盒子
        HBox emailHBox = new HBox();
        initEmailHBox(emailHBox);
        //移动电话横向盒子
        HBox movePhoneHBox = new HBox();
        initMovePhoneHBox(movePhoneHBox);
        //qq横向盒子
        HBox qqHBox = new HBox();
        initqqHBox(qqHBox);
        //微信横向盒子
        HBox weChatHBox = new HBox();
        initWeChatHBox(weChatHBox);

        //报名材料横向盒子
        HBox applyMaterialHBox = new HBox();
        initApplyMaterialHBox(applyMaterialHBox);
        //上传文件格式横向盒子
        HBox fileUploadHBox = new HBox();
        initFileUploadHBox(fileUploadHBox);
        //身份证横向盒子
        HBox IDHBox = new HBox();
        initIDHBox(IDHBox);
        //照片横向盒子
        HBox photoHBox = new HBox();
        initPhotoHBox(photoHBox);
        //学历证书盒子
        HBox eduBackgroundHBox = new HBox();
        initEduBackgroundHBox(eduBackgroundHBox);
        //底部横向盒子
        HBox bottomHBox = new HBox();
        initBottomHBox(bottomHBox);


        //滚动条盒子
        VBox scrollPaneVBox = new VBox();
        ScrollPane scrollPane = new ScrollPane();
        scrollPane.setContent(scrollPaneVBox);
        scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS);
        scrollPane.setPrefSize(preWidth,preHeight);

        //所有盒子放到滚动条盒子
        scrollPaneVBox.getChildren().addAll(topHBox,editApplyStuInfoHBox,accountHBox,applyNumHBox,nameHBox,genderHBox,birthdayHBox,IDTypeHBox,IDNumHBox,ofEnPHBox,emailHBox,movePhoneHBox,qqHBox,weChatHBox,applyMaterialHBox,fileUploadHBox,
                IDHBox,photoHBox,eduBackgroundHBox,bottomHBox);

        ObservableList<Node> children = this.getChildren();
        children.addAll(scrollPane);


    }

    /**
     * 初始化微信横向盒子
     * @param weChatHBox
     */
    private void initWeChatHBox(HBox weChatHBox) {

        weChatHBox.setSpacing(20);
        weChatHBox.setPadding(new Insets(20));

        //微信标签
        Label weChatLab = new Label("微信*");
        weChatLab.setPrefWidth(labDefaultWidth);//标签默认长度
        weChatLab.setFont(Font.font(null, FontWeight.BOLD, null, 20));

        //微信文本框
        TextField weChatTF = new TextField("qitongwei");
        weChatTF.setId("weChatTF");

        weChatHBox.getChildren().addAll(weChatLab, weChatTF);

    }

    /**
     * 初始化qq横向盒子
     * @param qqHBox
     */
    private void initqqHBox(HBox qqHBox) {

        qqHBox.setSpacing(20);
        qqHBox.setPadding(new Insets(20));
        //qq标签
        Label qqLab = new Label("qq*");
        qqLab.setPrefWidth(labDefaultWidth);//标签默认长度
        qqLab.setFont(Font.font(null, FontWeight.BOLD, null, 20));
        //qq文本框
        TextField qqTF = new TextField("2686542325");
        qqTF.setId("qqTF");
        qqHBox.getChildren().addAll(qqLab, qqTF);
    }


    /**
     * 底部横向盒子
     * @param bottomHBox
     */
    private void initBottomHBox(HBox bottomHBox) {
        bottomHBox.setPadding(new Insets(20));
        bottomHBox.setSpacing(20);
        bottomHBox.setAlignment(Pos.CENTER_RIGHT);
        //保存按钮
        Button saveBtn = new Button("保存");
        saveBtn.setPrefWidth(100);
        saveBtn.setPrefHeight(50);
        BackgroundFill saveBtnBackgroundFill = new BackgroundFill(Paint.valueOf("#00bFFF"),new CornerRadii(10),Insets.EMPTY);
        Background saveBtnBackground = new Background(saveBtnBackgroundFill);
        saveBtn.setBackground(saveBtnBackground);
        //保存按钮事件
        PageEditApplyStuInfoSaveBtnAction pageEditApplyStuInfoSaveBtnAction = new PageEditApplyStuInfoSaveBtnAction();
        pageEditApplyStuInfoSaveBtnAction.setPageEditApplyStuInfo(this);
        saveBtn.setOnAction(pageEditApplyStuInfoSaveBtnAction);
        saveBtn.setCursor(Cursor.HAND);
        //关闭按钮
        Button closeBtn = new Button("关闭");
        closeBtn.setPrefWidth(100);
        closeBtn.setPrefHeight(50);
        BackgroundFill closeBtnBackgroundFill = new BackgroundFill(Paint.valueOf("#00bFFF"),new CornerRadii(10),Insets.EMPTY);
        Background closeBtnBackground = new Background(closeBtnBackgroundFill);
        closeBtn.setBackground(closeBtnBackground);
        ObservableList<Node> children = bottomHBox.getChildren();
        children.addAll(saveBtn,closeBtn);
        //关闭按钮事件
        PageEditApplyStuInfoCloseBtnAction pageEditApplyStuInfoCloseBtnAction = new PageEditApplyStuInfoCloseBtnAction();
        closeBtn.setOnAction(pageEditApplyStuInfoCloseBtnAction);
        closeBtn.setCursor(Cursor.HAND);
    }

    /**
     * 学历证书横向盒子
     * @param eduBackgroundHBox
     */
    private void initEduBackgroundHBox(HBox eduBackgroundHBox) {
        eduBackgroundHBox.setPadding(new Insets(20));
        eduBackgroundHBox.setSpacing(20);
        //学历证书标签
        Label eduBackgroundLab = new Label("学历证书");
        eduBackgroundLab.setPrefWidth(labDefaultWidth);//标签默认长度
        eduBackgroundLab.setFont(Font.font(null,FontWeight.BOLD,null,20));

        //照片
        String eduUrl = "File:\\C:\\Users\\朱传博1120\\Desktop\\R-C.jpg";
        Image eduImage = new Image(eduUrl);
        ImageView eduIV= new ImageView(eduImage);
        eduIV.setFitWidth(300);
        eduIV.setFitHeight(200);


//        //预览按钮
//        Button lookBtn = new Button("预览");
//        lookBtn.setOnMouseEntered(new EventHandler<MouseEvent>() {
//            @Override
//            public void handle(MouseEvent event) {
//                lookBtn.setCursor(Cursor.HAND);
//            }
//        });
        //编辑按钮
        Button editBtn = new Button("编辑");
        //编辑按钮事件
        PageEditDegreeEditBtnAction pageEditDegreeEditBtnAction = new PageEditDegreeEditBtnAction();
        editBtn.setOnAction(pageEditDegreeEditBtnAction);
        editBtn.setCursor(Cursor.HAND);
        //删除按钮
        Button deleteBtn = new Button("删除");
        deleteBtn.setOnMouseEntered(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                deleteBtn.setCursor(Cursor.HAND);
            }


        });
        deleteBtn.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                Alert alert = new Alert(Alert.AlertType.WARNING);
                alert.setContentText("确定删除学历证书吗？");
                alert.show();
            }
        });

        ObservableList<Node> children = eduBackgroundHBox.getChildren();
        children.addAll(eduBackgroundLab,eduIV,editBtn,deleteBtn);

    }

    /**
     * 照片横向盒子
     * @param photoHBox
     */
    private void initPhotoHBox(HBox photoHBox) {
        photoHBox.setPadding(new Insets(20));
        photoHBox.setSpacing(20);
        //照片标签
        Label phoneLab = new Label("照片");
        phoneLab.setPrefWidth(labDefaultWidth);//标签默认长度
        phoneLab.setFont(Font.font(null,FontWeight.BOLD,null,20));

        //照片
        String phoneUrl = "File:\\C:\\Users\\朱传博1120\\Desktop\\1031-ivwfwmp3073225.jpg";
        Image phoneImage = new Image(phoneUrl);
        ImageView phoneIV= new ImageView(phoneImage);
        phoneIV.setFitWidth(300);
        phoneIV.setFitHeight(200);
//        //预览按钮
//        Button lookBtn = new Button("预览");
//        lookBtn.setOnMouseEntered(new EventHandler<MouseEvent>() {
//            @Override
//            public void handle(MouseEvent event) {
//                lookBtn.setCursor(Cursor.HAND);
//            }
//        });

        //编辑按钮
        Button editBtn = new Button("编辑");
        //编辑按钮事件
        PageEditPhoneEditBtnAction pageEditPhoneEditBtnAction = new PageEditPhoneEditBtnAction();
        editBtn.setOnAction(pageEditPhoneEditBtnAction);
        editBtn.setCursor(Cursor.HAND);
        //删除按钮
        Button deleteBtn = new Button("删除");
        deleteBtn.setOnMouseEntered(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                deleteBtn.setCursor(Cursor.HAND);
            }
        });
        deleteBtn.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                Alert alert = new Alert(Alert.AlertType.WARNING);
                alert.setContentText("确定删除照片吗");
                alert.show();
            }
        });
        ObservableList<Node> children = photoHBox.getChildren();
        children.addAll(phoneLab,phoneIV,editBtn,deleteBtn);

    }

    /**
     * 身份证横向盒子
     * @param idhBox
     */
    private void initIDHBox(HBox idhBox) {
        idhBox.setPadding(new Insets(20));
        idhBox.setSpacing(20);
        //身份证标签
        Label IDLab = new Label("身份证");
        IDLab.setPrefWidth(labDefaultWidth);//标签默认长度
        IDLab.setFont(Font.font(null,FontWeight.BOLD,null,20));

        //图片

        String idCardImageUrl ="File:\\C:\\Users\\朱传博1120\\Desktop\\20190625112514913.jpg";
        Image idImage = new Image(idCardImageUrl);
        ImageView idIV= new ImageView(idImage);
        idIV.setFitWidth(300);
        idIV.setFitHeight(200);
        idIV.setOnScroll(new EventHandler<ScrollEvent>() {
            @Override
            public void handle(ScrollEvent event) {
                if (event.getDeltaY() > 0) {
                    // 这里是向上滚动滚轮（即放大图片）
                } else {
                    // 这里是乡下滚动滚轮（即缩小图片）
                }
            }

        });

//        //预览按钮
//        Button lookBtn = new Button("预览");
//        lookBtn.setOnMouseEntered(new EventHandler<MouseEvent>() {
//            @Override
//            public void handle(MouseEvent event) {
//                lookBtn.setCursor(Cursor.HAND);
//            }
//        });
        //编辑按钮
        Button editBtn = new Button("编辑");
        //编辑按钮事件
        PageEditIDEditBtnAction pageEditIDEditBtnAction = new PageEditIDEditBtnAction();
        editBtn.setOnAction(pageEditIDEditBtnAction);
        editBtn.setCursor(Cursor.HAND);
        //删除按钮
        Button deleteBtn = new Button("删除");
        deleteBtn.setOnMouseEntered(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                deleteBtn.setCursor(Cursor.HAND);
            }
        });
        deleteBtn.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                Alert alert = new Alert(Alert.AlertType.WARNING);
                alert.setContentText("确定删除删除身份证吗？");
                alert.show();
            }
        });
        ObservableList<Node> children = idhBox.getChildren();
        children.addAll(IDLab,idIV,editBtn,deleteBtn);



    }

    /**
     * 上传文件格式横向盒子
     * @param fileUploadHBox
     */
    private void initFileUploadHBox(HBox fileUploadHBox) {
        fileUploadHBox.setPadding(new Insets(20));
        //上传文件格式标签
        Label fileUploadLab = new Label("上传文件格式：jpg、jpeg、gif、pdf、png(图片大小限制子在2MB以内)");
        fileUploadLab.setTextFill(Color.rgb(198,0,1));//字体颜色

        ObservableList<Node> children = fileUploadHBox.getChildren();
        children.addAll(fileUploadLab);
    }

    /**
     * 报名材料横向盒子
     * @param applyMaterialHBox
     */
    private void initApplyMaterialHBox(HBox applyMaterialHBox) {
        applyMaterialHBox.setPadding(new Insets(20));
        //报名材料标签
        Label applyMaterialLab = new Label("报名材料");
        //设置字体大小
        applyMaterialLab.setFont(Font.font(null,FontWeight.BOLD,null,22));
        applyMaterialLab.setTextFill(Color.rgb(198,0,1));//字体颜色
        ObservableList<Node> children = applyMaterialHBox.getChildren();
        children.addAll(applyMaterialLab);
    }


    /**
     * 移动电话横向盒子
     * @param movePhoneHBox
     */
    private void initMovePhoneHBox(HBox movePhoneHBox) {
        movePhoneHBox.setPadding(new Insets(20));
        movePhoneHBox.setSpacing(20);
        //移动电话标签
        Label movePhoneLab = new Label("移动电话*");
        movePhoneLab.setPrefWidth(labDefaultWidth);//标签默认长度
        movePhoneLab.setFont(Font.font(null,FontWeight.BOLD,null,20));
        //移动电话文本框
        TextField movePhoneTF = new TextField("12345678952");
        movePhoneTF.setId("movePhoneTF");
        ObservableList<Node> children = movePhoneHBox.getChildren();
        children.addAll(movePhoneLab,movePhoneTF);
    }

    /**
     * 电子邮件横向盒子
     * @param emailHBox
     */
    private void initEmailHBox(HBox emailHBox) {
        emailHBox.setPadding(new Insets(20));
        emailHBox.setSpacing(20);
        //电子邮箱标签
        Label emailLab = new Label("电子邮箱*");
        emailLab.setPrefWidth(labDefaultWidth);//标签默认长度
        emailLab.setFont(Font.font(null,FontWeight.BOLD,null,20));
        //电子邮箱文本框
        TextField emailTF = new TextField("zhangsan@qq.com");
        emailTF.setId("emailTF");
        ObservableList<Node> children = emailHBox.getChildren();
        children.addAll(emailLab,emailTF);
    }

    /**
     * 所属招生计划横向盒子
     * @param ofEnPHBox
     */
    private void initOfEnPHBox(HBox ofEnPHBox) {
        ofEnPHBox.setPadding(new Insets(20));
        ofEnPHBox.setSpacing(20);
        //所属招生计划标签
        Label ofEnPLab = new Label("所属招生计划*");
        ofEnPLab.setPrefWidth(labDefaultWidth);//标签默认长度
        ofEnPLab.setFont(Font.font(null,FontWeight.BOLD,null,20));
        //所属招生计划文本框
        TextField ofEnPTF = new TextField();
        ofEnPTF.setId("ofEnPTF");
        //选择招生计划按钮
        Button ofEnPBtn = new Button("选择招生计划");
        ofEnPBtn.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                Stage stage = new Stage();
                stage.show();


            }
        });
        ObservableList<Node> children = ofEnPHBox.getChildren();
        children.addAll(ofEnPLab,ofEnPTF,ofEnPBtn);
    }


    /**
     * 证件号码横向盒子
     * @param idNumHBox
     */
    private void initIDNumHBox(HBox idNumHBox) {
        idNumHBox.setPadding(new Insets(20));
        idNumHBox.setSpacing(20);
        //证件号码标签
        Label IDNumLab = new Label("证件号码*");
        IDNumLab.setPrefWidth(labDefaultWidth);//标签默认长度
        IDNumLab.setFont(Font.font(null,FontWeight.BOLD,null,20));
        //证件号码文本框
        TextField IDNumTF = new TextField("130703198809100910");
        IDNumTF.setId("IDNumTF");
        ObservableList<Node> children = idNumHBox.getChildren();
        children.addAll(IDNumLab,IDNumTF);
    }

    /**
     * 证件类型横向盒子
     * @param idTypeHBox
     */
    private void initIDTypeHBox(HBox idTypeHBox) {
        idTypeHBox.setPadding(new Insets(20));
        idTypeHBox.setSpacing(20);
        //证件类型标签
        Label IDTypeLab = new Label("证件类型*");
        IDTypeLab.setPrefWidth(labDefaultWidth);//标签默认长度
        IDTypeLab.setFont(Font.font(null,FontWeight.BOLD,null,20));
        //证件类型下拉框
        ComboBox IDTpeCB = new ComboBox<>();
        IDTpeCB.getItems().add("身份证");
        IDTpeCB.setId("IDTpeCB");
        IDTpeCB.getSelectionModel().selectFirst();
        ObservableList<Node> children = idTypeHBox.getChildren();
        children.addAll(IDTypeLab,IDTpeCB);
    }

    /**
     * 出身日期横向盒子
     * @param birthdayHBox
     */
    private void initBirthdayHBox(HBox birthdayHBox) {
        birthdayHBox.setPadding(new Insets(20));
        birthdayHBox.setSpacing(20);
        //出生日期标签
        Label birthdayLab = new Label("出生日期*");
        birthdayLab.setPrefWidth(labDefaultWidth);//标签默认长度
        birthdayLab.setFont(Font.font(null,FontWeight.BOLD,null,20));
        //日期选择器
        DatePicker birthdayDP = new DatePicker();
        birthdayDP.setEditable(false);//出生日期不可修改
        birthdayDP.setId("birthdayDP");
        ObservableList<Node> children = birthdayHBox.getChildren();
        children.addAll(birthdayLab,birthdayDP);
    }

    /**
     * 性别横向盒子
     * @param genderHBox
     */
    private void initGenderHBox(HBox genderHBox) {
        genderHBox.setPadding(new Insets(20));
        genderHBox.setSpacing(20);
        //性别标签
        Label genderLab = new Label("性别*");
        genderLab.setPrefWidth(labDefaultWidth);//标签默认长度
        genderLab.setFont(Font.font(null,FontWeight.BOLD,null,20));
        //性别下拉框
        ComboBox genderCB = new ComboBox<>();
        genderCB.getItems().add("男");
        genderCB.getItems().add("女");
        genderCB.setId("genderCB");
        genderCB.getSelectionModel().selectFirst();
        ObservableList<Node> children = genderHBox.getChildren();
        children.addAll(genderLab,genderCB);
    }

    /**
     * 姓名横向盒子
     * @param nameHBox
     */
    private void initNameHBox(HBox nameHBox) {
        nameHBox.setPadding(new Insets(20));
        nameHBox.setSpacing(20);
        //姓名标签
        Label nameLab= new Label("姓名*");
        nameLab.setPrefWidth(labDefaultWidth);
        nameLab.setFont(Font.font(null,FontWeight.BOLD,null,20));
        //姓名文本框
        TextField nameTF = new TextField("张三");
        nameTF.setId("nameTF");
        nameTF.setEditable(false);//不可更改
        ObservableList<Node> children = nameHBox.getChildren();
        children.addAll(nameLab,nameTF);

    }

    /**
     * 报名编号横向盒子
     * @param applyNumHBox
     */
    private void initApplyNumHBox(HBox applyNumHBox) {
        applyNumHBox.setPadding(new Insets(20));
        applyNumHBox.setSpacing(20);
        //报名编号标签
        Label applyNumLab = new Label("报名编号");
        applyNumLab.setPrefWidth(labDefaultWidth);
        applyNumLab.setFont(Font.font(null,FontWeight.BOLD,null,20));
        //报名编号文本框
        TextField applyNumTF = new TextField("123456");
        applyNumTF.setId("applyNumTF");
        ObservableList<Node> children = applyNumHBox.getChildren();
        children.addAll(applyNumLab,applyNumTF);
    }

    /**
     * 帐号电子邮箱盒子
     * @param accountHBox
     */
    private void initAccountHBox(HBox accountHBox) {
        accountHBox.setPadding(new Insets(20));
        accountHBox.setSpacing(20);
        //账号（电子邮箱）标签
        Label accountLab = new Label("帐号（电子邮箱）");
        accountLab.setPrefWidth(labDefaultWidth);
        accountLab.setFont(Font.font(null,FontWeight.BOLD,null,20));
        //账号（电子邮箱）文本框
        TextField accountTF = new TextField("zhangsan@126.com");
        accountTF.setId("accountTF");
        ObservableList<Node> children = accountHBox.getChildren();
        children.addAll(accountLab,accountTF);
    }

    /**
     * 编辑报名学员信息横向盒子
     * @param editApplyStuInfoHBox
     */
    private void initEditApplyStuInfoHBox(HBox editApplyStuInfoHBox) {
        editApplyStuInfoHBox.setPadding(new Insets(20));
        //编辑报名学员信息标签
        Label editApplyStuInfoLab = new Label("编辑报名学员信息");
        //设置字体大小
        editApplyStuInfoLab.setFont(Font.font(null, FontWeight.BOLD,null,22));
        editApplyStuInfoLab.setTextFill(Color.rgb(198,0,1));//字体颜色
        editApplyStuInfoHBox.getChildren().addAll(editApplyStuInfoLab);

    }

    /**
     * 顶部横向盒子
     * @param topHBox
     */
    private void initTopHBox(HBox topHBox) {

        topHBox.setSpacing(20);
        topHBox.setPadding(new Insets(20));
        //顶部标签
        Label topLab = new Label("当前位置：🏠>招生管理>报名学员管理>编辑报名信息");
        topLab.setFont(new Font(20));//设置字体大小
        ObservableList<Node> children = topHBox.getChildren();
        children.addAll(topLab);
    }
}
